<?php
/**
 * ShopperGroups Classes Controller
 *
 * PHP 5.2+
 *
 * Copyright 2012
 * @date 21-April-2012
 * @author
 * @property Auth $Auth
 * @version 0.0.1
 **/
class ShopperGroupsController extends AppController 
{

    public $sN = 'ShopperGroup'; 
    public $pN = 'shopper_group';
    public $lN = 'shopper_groups';    
    
    public function beforeFilter() {
        parent::beforeFilter();
        $this->loadModel("ShopperGroup");
        $this->set('sN', $this->sN);        
        $this->set('pN', $this->pN);
        $this->set('lN', $this->lN);        
    }
    public function admin_index() {
        $values = $this->paginate($this->sN,array());
      	$this->set('values', $values);
    }
    public function admin_add(){
        if(!empty($this->data)) {
            $this->request->data["ShopperGroup"]['created_by'] = $this->Auth->user('id');
            if($this->ShopperGroup->save($this->data)) {
                $this->Session->setFlash(__('Updated Successfully', true));
                $this->redirect(array('controller' => 'shopper_groups', 'action' => 'index', 'admin' => true));
            }
        }
    }
    public function admin_edit($id=null){
        if(empty($this->data)) {
            $this->request->data = $this->ShopperGroup->read(null, $id);
        }else{
            $this->ShopperGroup->id = $id;
            if($this->ShopperGroup->save($this->data)) {
                $this->Session->setFlash(__('Updated Successfully', true));
                $this->redirect(array('controller' => 'shopper_groups', 'action' => 'index', 'admin' => true));
            }
        }
    }
    public function admin_delete($id = null) {
        if(!$id){
            $this->Session->setFlash(__('Invalid Shopper group id', true));
            $this->redirect(array('controller' => 'shopper_groups', 'action' => 'index', 'admin' => true));
        }else{
            $this->ShopperGroup->id = $id;
            if($this->ShopperGroup->delete()) {
                $this->Session->setFlash(__('The shopper group has been deleted', true));
                $this->redirect(array('controller' => 'shopper_groups', 'action' => 'index', 'admin' => true));
            }
        }
    }
}